Reading Assignment 3

OpenMP Advanced

Write your answers in a PDF and upload the document on Gradescope for submission. The due date is given on Gradescope. Each question is worth 10 points.

Please watch the videos 13 through 18 and the slides before answering these questions.

Starter code for all the questions.

Slide Deck

  1. Why is
    #pragma omp task
    

    typically preceded by

    #pragma omp single
    

    ?

  2. In OpenMP, firstprivate variables must be initialized inside the task. True/False? Explain.
  3. In tree_postorder.cpp, explain why we use the shared clause on line 65 and 69.

For the next questions, please open slide 29 in Lecture_05.pdf. Then answer these questions:

  1. Task T2 comes after T1. Always/Never/Sometimes. Explain.
  2. Task T2 comes after T4. Always/Never/Sometimes. Explain.
  3. Task T5 comes after T1. Always/Never/Sometimes. Explain.
  4. Tasks T4 and T5 may run concurrently. Yes/No/It depends. Explain.
  5. Task T5 comes after T1 and T3. Always/Never/Sometimes. Explain.
  6. This program prints out “d=6”. Yes/No/It depends. Explain.
  7. When both are correct, atomic is preferred over reduction in a for loop. True/False? Explain.
  8. Complete the todo in entropy.cpp. See lines 22, 31, 39, and 50. Turn in your code.

Slide Deck. Make sure you watch the corresponding video.

  1. Parallelize bitonic_sort_lab.cpp using OpenMP. Follow the instructions in the slides. You should make at least the following changes: parallelize the j loop on line 86. Split the i loop on line 84. Modify the function BitonicSortPar to parallelize the i loop on line 169. Modify line 184 by adding an if statement. Add and parallelize the j loop as explained on slide 44. At the end, you should have three new #pragma omp directives. Turn in your code. Turn in the output of your code without the -DNDEBUG compile option.

If you compile your code without -DNDEBUG, this will keep the assert at the end. If you implement your code correctly, you should pass the assert test at the end.

With the -DNDEBUG option, the code will sort a longer array. You should see a speed up when using multiple threads. Run your code using

export OMP_NUM_THREADS=4; ./bitonic_sort